1 /*
2 * Copyright (c) 2002-2003 The XDoclet Team.
3 * All rights reserved.
4 */
5
6 package xdoclet;
7
8 import junit.framework.TestCase;
9
10 /***
11 * Test for {@link PackageSubstitution}.
12 *
13 * @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a>
14 * @author <a href="mailto:mbo at jcs.be">Mathias Bogaert</a>
15 * @version $Revision: 1.6 $
16 */
17 public class PackageSubstitutionTest extends TestCase {
18 public void testNullPackageNameMatch() {
19 PackageSubstitution sub = new PackageSubstitution();
20 try {
21 sub.getSubstitutedPackageName(null);
22 fail("no null check for sub.getSubstitutedPackageName(null);");
23 }
24 catch (IllegalArgumentException ex) {
25 // good
26 }
27
28 try {
29 sub.getSubstitutedPackageName("bing.foo.bar.bong");
30 fail("from not set, so no pattern is compiled, a NullPointerException is thrown");
31 }
32 catch (IllegalStateException ex) {
33 // good
34 }
35
36 try {
37 sub.setFrom(null);
38 fail("sub.setFrom(null) does not throw IllegalArgumentException");
39 }
40 catch (IllegalArgumentException ex) {
41 // good
42 }
43
44 sub.setFrom("foo.bar");
45 String packageName = sub.getSubstitutedPackageName("bing.foo.bar.bong");
46 assertEquals("bing..bong", packageName); // todo : check for 2 dots and remove one??
47 }
48
49 public void testGetSubstitutedPackageNameMatchCase() {
50 PackageSubstitution sub = new PackageSubstitution();
51 sub.setFrom("foo.BAR");
52 sub.setTo("ZAP.bang");
53 String packageName = sub.getSubstitutedPackageName("bing.foo.bar.bong");
54 assertEquals("bing.zap.bang.bong", packageName);
55 }
56
57 public void testGetSubstitutedPackageNameMatch() {
58 PackageSubstitution sub = new PackageSubstitution();
59 sub.setFrom("foo.bar");
60 sub.setTo("zap.bang");
61 String packageName = sub.getSubstitutedPackageName("bing.foo.bar.bong");
62 assertEquals("bing.zap.bang.bong", packageName);
63 }
64
65 public void testGetSubstitutedPackageNameNoMatch() {
66 PackageSubstitution sub = new PackageSubstitution();
67 sub.setFrom("foo.bar");
68 sub.setTo("zap.bang");
69 String packageName = sub.getSubstitutedPackageName("bing.bung.bong");
70 assertEquals(null, packageName);
71 }
72 }
This page was automatically generated by Maven